function formatName(name) {
	var newName  = name;
	if(name != null && name.length >10) {
		var newName = name.substring(0, 7) + "..." + name.substring(name.lastIndexOf("."));
	}
	return newName;
}

/*function scrollTop(obj){
	var obj = document.getElementById(obj);
	var y = obj;
	var h = 0;
	while(y){
		h += y.offsetTop; 
		y = y.offsetParent; 
	}
	window.onscroll = function(){
		var s = Math.max(document.documentElement.scrollTop || document.body.scrollTop);
		if(s > h && obj.fix || s <= h && !obj.fix)
			return;
		obj.style.position = obj.fix ? "" : "fixed";
		obj.fix = !obj.fix;
	};

}*/

function id(elem) {
	return document.getElementById(elem);
}
function show(elem) {elem.style.display = "";}
function hide(elem) {elem.style.display = "none";}
function next( elem ) {
    do {
        elem = elem.nextSibling;
    } while ( elem && elem.nodeType != 1 );
    return elem;
}

function switchReply(areaId, user, loginAction) {
	if(user == null || user == "" ) {
		window.location.href=loginAction;
		return;
	}
	var elem = $("#" + areaId);
	if(elem.is(":visible")) {
		elem.hide();
	} else {
		elem.show();
	}	
}



function get_rate(rate, id){
	rate=rate.toString();
	var s;
	var g;
	$("#g_" + id).show();
	if (rate.length>=3){
		s=10;	
		g=0;
		$("#g_" + id).hide();
	}else if(rate=="0"){
		s=0;
		g=0;
	}else{
		s=rate.substr(0,1);
		g=rate.substr(1,1);
	}
	$("#s_" + id).text(s);
	$("#g_" + id).text("."+ g);
	
	$("#big_rate_up_" + id).animate({width:(parseInt(s)+parseInt(g)/10) * 7.5,height:26},1000);
	$("#big_rate_bak_"+id+" b").each(function(){
		
		$(this).mouseover(function(){
			$("#big_rate_up_"+id).width($(this).attr("rate") * 7.5 );
			$("#s_" + id).text($(this).attr("rate"));
			$("#g_" +id).text(".0");
		}).click(function(){			
			s = $(this).attr("rate");
			$("#offerRate").val(s);
			g = "0";
			$("#s_"+id).text(s);
			$("#g_"+id).text("."+ g);
			$("#big_rate_up_"+id).width((parseInt(s)+parseInt(g)/10) * 7.5);
		});
	});
	$("#big_rate_bak_"+id).mouseout(function(){
		$("#s_"+id).text(s);
		$("#g_"+id).text("."+ g);
		$("#big_rate_up_"+id).width((parseInt(s)+parseInt(g)/10) * 7.5);
	});
}
function up_rate(rate, id){
	$("#big_rate_up_"+id).width("0");
	get_rate(rate);
}

function showRate(id, s, g) {
	$("#big_rate_up_" + id).animate({width:(parseInt(s)+parseInt(g)/10) * 7.5,height:26},1000);
}

function showRateSmall(id, s, g) {
	$("#big_rate_up_" + id).animate({width:(parseInt(s)+parseInt(g)/10) * 5,height:10},1000);
}

function scoreComment(commId, flag) {
	var numNodeId = (flag==1?"goodComm"+ commId:"badComm" + commId);
	var numNuode = $("#" + numNodeId); 
	$.ajax({ 
         type: "POST", 
         url: contextPath + "/scoreComment", 
         data:"comment.id="+commId + "&flag=" + flag, 
         success: function(msg){ 
			msg = msg.replace("[","").replace("]","");
			var obj = $.parseJSON(msg);
			if(obj.num != -1) {
				numNuode.text("(" + obj.num + ")");
			}  
        } 
    }); 
}

function refreshCaptcha(){
	 $('#jcaptcha').attr('src', 'jcaptcha.jpg?' + Math.random());
}

function addCommentPhotos(id, targetId) {
	var photoList = $("#" + targetId);
	var index = $(".commentPhoto").length;
	photoList.append('<input class="commentPhoto"  type="hidden" name="photos['+index+'].id" value="'+id+'">');
}


function shareMy(userName,actionName, login) {
	if(userName != null && userName != '' ) {
		window.location.href=actionName;
	} else {
		window.location.href=login;
	}
	return;
	
}

function showFeedBackTailsInfo(id) {
	$("#feedback_tails" + id).show();
}

function hideFeedBackTailsInfo(id) {
	$("#feedback_tails" + id).hide();
}

